/**
 * @author Steve Gao<gaofu@parllay.com>
 */
const BaseHandler     = require('../base-handler');
const HTTP_VERBS      = require('../../../constants').HTTP_VERBS;

class WallAssetHandler extends BaseHandler {

    get pattern() {
        return '/walls/:wall_id/assets/:asset_id';
    }

    doGET(request, response) {
        var assetId = request.params.asset_id;
        this.Controller.getAssetById(assetId, (result) => {
            response.end(JSON.stringify(result));
        });
    }

    doPOST(request, response) {
        var assetId = request.params.asset_id;
        var userId = request.session.user.id;
        var wallId = request.params.wall_id;
        this.Controller.updateAssetById(wallId, assetId, request.body, userId, (result) => {
            response.json(result);
        });
    }

    setup() {
        this.registerVerb(HTTP_VERBS.GET, this.doGET);
        this.registerVerb(HTTP_VERBS.POST, this.doPOST);
    }
}

module.exports = WallAssetHandler;